<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Memcache
 *
 * @author ananda
 */
class Data_Collection_Pdo extends Data_Collection
{
    public $cursor;
    public $row;
    public $total;

    public $fetch_mode = PDO::FETCH_ASSOC;

    public function init() {
        $this->handler->setFetchMode($this->fetch_mode);
        $this->row   = $this->handler->fetch();
        $this->total = $this->handler->rowCount();
        $this->rewind();
    }

    /**
     * 迭代器接口
     * @return mixed
     */
    public function current()
    {
        return $this->row;
    }

    /**
     * 迭代器接口
     * @return mixed
     */
    public function key()
    {
        return $this->cursor;
    }

    /**
     * 迭代器接口
     * @return void
     */
    public function next()
    {
        $this->cursor++;
        $this->row = $this->handler->fetch();
    }

    /**
     * 迭代器接口
     * @return void
     */
    public function rewind()
    {
        $this->cursor = 0;
    }

    /**
     * 迭代器接口
     * @return boolean
     */
    public function valid()
    {
        return $this->total > $this->cursor;
    }

    public function rowCount()
    {
        return $this->total;
    }

    public function getArray()
    {
        return $this->handler->fetchAll();
    }

}
